#include "MainScene.h"
#include "GameScene.h"

USING_NS_CC;

CCScene* MainScene::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    MainScene *layer = MainScene::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool MainScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("candy.plist");
    
	CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    CCMenuItemFont *pCloseItem = CCMenuItemFont::create("start game",
                                        this,
                                        menu_selector(MainScene::menuClick));
    
	pCloseItem->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);
    
    return true;
}


void MainScene::menuClick(CCObject* pSender)
{
	CCDirector::sharedDirector()->replaceScene(GameScene::create());
}
